package com.nbst.comnutil;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.collections4.Predicate;

public class BeanNotEqualPredicate<T> implements Predicate<T> {
 
	private final String field;
	private final Object param;
	
	BeanNotEqualPredicate(String field,Object param){
		this.field = field;
		this.param = param;
	}
	
	
	@Override
	public boolean evaluate(T object) {
		try {
			Object propertyValue = PropertyUtils.getProperty(object, field);
			return propertyValue == null || propertyValue != param && !propertyValue.equals(param);
		} catch (IllegalAccessException | InvocationTargetException
				| NoSuchMethodException e) {
			throw new RuntimeException(e);
		}
	}
}